<?php session_start(); $_SESSION['page'] = 'catalog';?>
<?php
    $category = $_GET['category'];
    $searchtext = $_GET['searchtext'];
    //$location = $_GET['location'];
    require('db_connection.php');
    if($category != 'All' && $category !='Keyword')
    {
      $query = "SELECT * FROM tblcollection WHERE libraryNo LIKE '$libraryNo' AND $category LIKE '%$searchtext%'";
    }
    elseif ($category == 'All' && $searchtext == 'All')
   {
        $query = "SELECT * FROM tblcollection WHERE libraryNo LIKE '$libraryNo'";
   }
  else
  {
    $query= "SELECT * FROM tblcollection WHERE libraryNo=$libraryNo AND title LIKE '%$searchtext%' OR author LIKE '%$searchtext%' OR subject LIKE '%$searchtext%' ";
  }
  
    $result = mysql_query($query);
    //$result= mysql_query("SELECT * FROM tblcollection");
    
   $ctr1 = mysql_num_rows($result);
   /*
$ctr1 = "SELECT MAX(materialID) FROM tblcollection";
   $ctr2 = mysql_query($ctr1);
   while ($row = mysql_fetch_array($ctr2))
   {
     $ctr1 = $row['MAX(materialID)'];
     echo $ctr1;
   }
*/
   

?>

<!doctype html public "-//W3C//DTD HTML 4.01//EN">

<html>

   <head>
      <title>Catalog Search</title>
      <meta http-equiv="generator" content="PHP Designer 2005" />
      <style type="text/css">
        @import url(style.css);
      </style>
   </head>

    <script LANGUAGE=javascript>
    <!--
     function check()
     {
        if(document.search_form.searchtext.value=="" )
        {
          alert('Please fill the search box.');
          return false;
        }
        return true;
     }
     //-->
    </script>


   <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000" class=''>

    <form method='get' action='cataloglist.php' name='search_form' onSubmit="return check();">
   <table width='80%' align='center' class='content'>
        <tr><td colspan='2'><img src='images/banner1.jpg'></td></tr>
            <tr><td align='right' colspan='2' class='logborder'><?php require ('loginout.php');?></td></tr>
            <tr class='menuborder'><td width='90%'><img src='images/searchresult.png'></td><td><?php  require('buttons.php'); ?></td></tr>
            <tr><td colspan='2' class='bodyborder'>
            <table align='center'>
                <tr><td height='30'></td></tr>
                <tr><td>Search By</td>
                    <td><select name='category'>
                        <option>All</option>
                        <option>Title</option>
                        <option>Author</option>
                        <option>Subject</option>
                        <option>Keyword</option>
                        </select>
                    </td>
                    <td><input type='text' name='searchtext' size='40'></td>
                    <td><input type='submit' value='Search' class='tool'></td></form>
                </tr>
                <tr><td height='15'></td></tr>
            </table>
            </td>
        </tr>
        <tr><td colspan='2'>
            <table align='center' width='60%'>
                <tr><td height='30'></td></tr>
                <tr><th colspan='4'>Search Result</th></tr>
                <tr><td height='15'></td></tr>
                <tr>
                <td>
            <?php echo "<form method='post' action='delete.php?page=catalog&catalogCtr=$ctr1'>";
                    $ctr=1;
                          while ($row = mysql_fetch_array($result))
                            {
                                        $title=$row['title'];
                                        $author = $row['author'];
                                        $publisher = $row['publisher'];
                                        $materialID = $row['materialID'];
                                        
                                        echo"<tr class='td1'><td><input type='checkbox' name='mat[$ctr]' value='$materialID' >".$ctr.".  $materialID <a href='catalogdetail.php?materialID=$materialID'> ".$title."</a></td></tr>";
                            echo"<tr class='td2'><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by &nbsp;".$author.", ".$publisher."</td></tr>";
                            echo"</tr>";
                            $ctr++;
                                        //$libraryNo = $row['libraryNo'];
                                        //$libraryName = $row['libraryName'];
                                        //echo "<form action='delete.php?page=library' method='post'>";
                                        //echo "<tr><td><input type='checkbox' name='libraryName[$libraryNo]' value='$libraryNo'>$libraryName</td></tr>";
                                        //echo"<a href=editlibrary.php?libraryNo=$libraryNo>$libraryName</a><br />";
                                        //echo"<option value=$libraryNo>"." $location "." ";

                            }

                    ?>
                <tr><td height='15'></td></tr>
                <tr><td colspan='2' align='right'><input type='submit' value='Delete' class='tool'></td></tr></td>
                </tr>
            </table>
            </td>
        </tr>
        <tr><td align='center' colspan='2'><?php require ('copyright.php')?></td></tr>
    </table>
    </form>

   </body>
</html>
